import {useState,useEffect, FC} from 'react'
import { Table } from 'antd';
import AssetSearch from '../AssetSearch'
import PaginationList from '@/components/PaginationList'
import { useRequest } from 'ahooks';
import { useSearchParams } from 'react-router-dom';
import { getSubdomainInfo } from '@/api/asset';
const SubDomain: FC = () => {
    // 资产表格
    const columns = [
        {
          title: '子域名',
          dataIndex: 'host',
          key: 'host',
          render:(_,{host})=>{
            return (
              <div>
                <a href={`https://${host}`} target="_blank" rel="noreferrer">{host}</a>
              </div>
            )
          }
        },
          {
            title: '记录类型',
            dataIndex: 'type',
            key: 'type',
          },
          {
            title: '记录值',
            dataIndex: 'value',
            key: 'value',
          },
          {
            title: 'IP',
            dataIndex: 'ip',
            key: 'ip',
            render:(_,{ip})=>{
              return (
                <div>
                  <a href={`http://${ip}`} target="_blank" rel="noreferrer">{ip}</a>
                </div>
              )
            }
          },
        {
            title: '时间',
            dataIndex: 'time',
            key: 'time',

          },

      ];
      const [assetDomainInfo,setAssetDomainInfo] = useState([])
      const [searchParams] = useSearchParams()
      const [PageTotal,setPageTotal] = useState(0)

      const {run} = useRequest(async ()=>{
        const search = searchParams.get('search') || ""
        const page = parseInt(searchParams.get('page') || "1")
        const pageSize = parseInt(searchParams.get('size') || "10")
        const res = await getSubdomainInfo({pageIndex:page,pageSize,search})
        return res
      },{
        manual:true,
        onSuccess(data:any){
            setAssetDomainInfo(data?.data?.list)
            setPageTotal(data?.data?.total)
        }
      })
      useEffect(()=>{
          run()
      },[searchParams])
    return (
        <div>
            <AssetSearch assetInfo={assetDomainInfo} />
            <div>
            <Table dataSource={assetDomainInfo} columns={columns} pagination={false} />
            <PaginationList total={PageTotal} />
            </div>
        </div>
    )
}
export  default SubDomain